From Etienne: Vito cleansps. Misc warning fixes.
authorrobertl <robertl@f51c46e8-681c-474f-0cfe-069cfd0219fb>
Thu, 30 Jun 2005 22:51:45 +0000 (22:51 +0000)
committerrobertl <robertl@f51c46e8-681c-474f-0cfe-069cfd0219fb>
Thu, 30 Jun 2005 22:51:45 +0000 (22:51 +0000)
gpsbabel/an1.c
gpsbabel/bcr.c
gpsbabel/defs.h
gpsbabel/maggeo.c
gpsbabel/mapsource.c
gpsbabel/pathaway.c
gpsbabel/vecs.c
gpsbabel/vitosmt.c

index 63035f4c7b0beb47fad4cf671afd51dbcf149800..cb98a17a7c0224f3b945ece2f8f8258c650118c4 100644 (file)
@@ -277,6 +277,7 @@ static an1_waypoint_record *Alloc_AN1_Waypoint( ) {
        result = (an1_waypoint_record *)xcalloc( sizeof(*result), 1 );
        result->base.copy = Copy_AN1_Waypoint;
        result->base.destroy = Destroy_AN1_Waypoint; 
+       return result;
 }
        
 static an1_vertex_record *Alloc_AN1_Vertex();
@@ -297,6 +298,7 @@ static an1_vertex_record *Alloc_AN1_Vertex() {
        result = (an1_vertex_record *)xcalloc( sizeof( *result), 1 );
        result->base.copy = Copy_AN1_Vertex;
        result->base.destroy = Destroy_AN1_Vertex;
+       return result;
 }
                        
 
@@ -320,6 +322,7 @@ static an1_line_record *Alloc_AN1_Line( ) {
        result = (an1_line_record *)xcalloc( sizeof(*result), 1 );
        result->base.copy = Copy_AN1_Line;
        result->base.destroy = Destroy_AN1_Line;
+       return result;
 }
 
 
@@ -451,7 +454,7 @@ static void Write_AN1_Line( FILE *f, an1_line_record *line ) {
        len = strlen( line->name );
        WriteShort( f, len );
        WriteString( f, line->name );
-       WriteShort( f, line->lineweight );
+       WriteShort( f, (short) line->lineweight );
        WriteLong( f, line->linestyle );
        WriteLong( f, line->linecolor );
        WriteLong( f, line->unk5 );
@@ -507,7 +510,7 @@ static void Read_AN1_Header( FILE *f ) {
 
 static void Write_AN1_Header( FILE *f ) {
        WriteShort( f, 11557 );
-       WriteShort( f, atoi( output_type ) );
+       WriteShort( f, (short) atoi( output_type ) );
 }
 
 static void Read_AN1_Bitmaps( FILE *f ) {
@@ -632,7 +635,7 @@ static void Read_AN1_Lines( FILE *f ) {
                 rte_head = route_head_alloc();
                rte_head->an1_extras = (an1_base *)(void *)rec;
                 route_add_head(rte_head);
-               for (j = 0; j < rec->pointcount; j++ ) {
+               for (j = 0; j < (unsigned) rec->pointcount; j++ ) {
                        vert = Alloc_AN1_Vertex();
                        Read_AN1_Vertex( f, vert );
                        
index 0ef698e8125615f79c2994ccfe2df50341e6006d..9f4a54b47022b2942fb61835467120cc5c1b1444 100644 (file)
@@ -395,8 +395,7 @@ bcr_route_header(const route_head *route)
        char buff[128], symbol[32];
        
        curr_rte_num++;
-       if (curr_rte_num != target_rte_num) return;
-       
+       if (curr_rte_num != target_rte_num) return;     
        
        bcr_write_line(fout, "[CLIENT]", NULL, NULL);                   /* client section */
 
@@ -481,7 +480,7 @@ bcr_data_write(void)
            if (rtenum_opt != NULL)
            {
                target_rte_num = atoi(rtenum_opt);
-               if ((target_rte_num > route_count()) || (target_rte_num < 1))
+               if (((unsigned)target_rte_num > route_count()) || (target_rte_num < 1))
                    fatal(MYNAME ": invalid route number %d (1..%d))!\n", 
                        target_rte_num, route_count());
            }
index 72c5ce53aa507e3a7c408c254a1b4936eacf3d6a..afdb0c510e506fe7e78cb84a98111170824ef91f 100644 (file)
@@ -71,8 +71,9 @@ typedef enum {
 } gpsdata_type;
 
 typedef enum {
-       fix_unknown,
-       fix_2d, 
+       fix_unknown=-1,
+       fix_none=0,
+       fix_2d=1,       
        fix_3d,
        fix_dgps,
        fix_pps
@@ -556,6 +557,7 @@ char *strsub(const char *s, const char *search, const char *replace);
 char *gstrsub(const char *s, const char *search, const char *replace);
 void rtrim(char *s);
 signed int get_tz_offset(void);
+time_t mkgmtime(struct tm *t);
 time_t current_time(void);
 signed int month_lookup(const char *m);
 const char *get_cache_icon(const waypoint *waypointp);
index f9496010784a189fc9c73006ff8e26371d617ed1..382719d82e0edff1017bf2bc098fe111c6a1bf42 100644 (file)
@@ -125,7 +125,6 @@ static void
 maggeo_waypt_pr(const waypoint *waypointp)
 {
        char obuf[4096];
-       char dtbuf[10];
        double ilon, ilat;
        double lon, lat;
        int lon_deg, lat_deg;
@@ -216,7 +215,6 @@ strconsume(char *instr, int *eaten)
        const char *origstr = instr;
        char *s = instr;
        char *e = instr;
-       int ct;
 
        while (e && *e && *e != ',')
                *e++;
index f637cb0eaf5f15bc13a05914bf1ea1ff205a3bd0..0a913cc88a03f94aabe97591cc6eb98c0b466fef 100644 (file)
@@ -446,12 +446,12 @@ mps_fileHeader_w(FILE *mps_file, int mps_ver)
        strcpy(hdr+7,"Oct 20 1999");
        strcpy(hdr+19,"12:50:33");
        if (mps_ver == 4) {
-               hdr[1] = 0x96;                                  /* equates to V4.06 */
+               hdr[1] = (char) 0x96;                                   /* equates to V4.06 */
                strcpy(hdr+7,"Oct 22 2001");
                strcpy(hdr+19,"15:45:33");
        }
        if (mps_ver == 5) {
-               hdr[1] = 0xF4;                                  /* equates to V5.0 */
+               hdr[1] = (char) 0xF4;                                   /* equates to V5.0 */
                strcpy(hdr+7,"Jul  3 2003");
                strcpy(hdr+19,"08:35:33");
        }
index fd779078c165fd2512f5476d327de697c0a2e226..92580d86d546fdccd941afd7202dce2158c25d7b 100644 (file)
@@ -79,22 +79,24 @@ is_fatal(int is, const char *msg, ... )
 
 #if PPDB_DEBUG
 static void
-internal_debug(const char *filename, int fileline, const char *format, ... )
+internal_debug1(const char *filename, int fileline)
+{
+       static int ct=1;
+       printf("DBG(%d): file %s, line %d: ", ct++, filename, fileline);
+}
+static void
+internal_debug2(const char *format, ... )
 {
        va_list args;
-       char *buff;
-       static int ct;
-       
-       buff = (char *) xmalloc(1024);
+
        va_start(args, format);
-       vsnprintf(buff, 1023, format, args);
-       printf("DBG(%d): %s in file %s, line %d\n", ct++, buff, filename, fileline);
+       vprintf(format, args);
+       puts("");
        va_end(args);
-       xfree(buff);
 }
-#define DBG(fmt, args...) internal_debug (__FILE__, __LINE__, fmt, ## args )
+#define DBG    internal_debug1(__FILE__, __LINE__);internal_debug2
 #else
-#define DBG(fmt, args...)
+#define DBG    # ;
 #endif
 
 
@@ -131,8 +133,8 @@ char *ppdb_strcat(char *dest, char *src, char *def, int *size)
 
 #define STR_POOL_SIZE 16       /* !!! any power of 2 !!! */
 
-static char *str_pool[STR_POOL_SIZE] = {};
-static size_t str_pool_s[STR_POOL_SIZE] = {};
+static char *str_pool[STR_POOL_SIZE];
+static size_t str_pool_s[STR_POOL_SIZE];
 static int str_poolp = -1;
 
 void str_pool_init(void)
@@ -220,7 +222,7 @@ char *ppdb_fmt_float(const double val)
 char *ppdb_fmt_degrees(char dir, double val)
 {
        char *str = str_pool_get(32);
-       int deg = abs(val);
+       int deg = fabs(val);
        double min = 60.0 * (fabs(val) - deg);
        int power = 0;
        double fx = min;
@@ -602,7 +604,7 @@ static void ppdb_write_wpt(const waypoint *wpt)
            buff = ppdb_strcat(buff, tmp, "", &len);
 
        len = strlen(buff) + 1;
-       rec = new_Record(0, 0, ct++, len, (const ubyte *) buff);
+       rec = new_Record(0, 0, (udword)ct++, (uword)len, (const ubyte *) buff);
 
        if (rec == NULL) 
            fatal(MYNAME ": libpdb couldn't create record\n");
index 02c8bb51dd46c56ab3a1236f06367ef7fb0619c3..cbd7bf9b51afbf1fb4402caf900901bbc8d72223 100644 (file)
@@ -726,7 +726,6 @@ disp_formats(int version)
 {
        vecs_t **svp;
        vecs_t *vec;
-       style_vecs_t *svec;
        int i, vc = 0;
 
        switch(version) {
index fe51c783c107dc2c7368857680c5c5e0040ff9f9..562aeab04a1218f81d65efdcb304e6e86105d8f3 100644 (file)
 #define MYNAME "vitosmt"
 #include "defs.h"
 
-FILE                   *infile =0;
-FILE                   *ofs    =0;
-unsigned long  count   =0;
-
-const size_t vitosmt_headersize                =24;
-const size_t vitosmt_datasize          =64;
-const double mile2km           =1.609344;              /* mile/h to kilometer/h */
-const double kts2mps =0.51444444444444444;     /* knots to m/s */
-const double mph2mps           =0.447039259;   /* mile/h to m/s     */
+static FILE                            *infile =0;
+static FILE                            *ofs    =0;
+static long                            count   =0;
+
+const long                             vitosmt_version                 =2;
+const long                             vitosmt_subversion              =1000;
+const size_t                   vitosmt_headersize              =24;
+const size_t                   vitosmt_datasize                =64;
+const double mile2km   =1.609344;                              /* mile/h to kilometer/h */
+const double kts2mps   =0.5144444444444444444; /* knots to m/s */
+const double mph2mps   =0.447039259;                   /* mile/h to m/s     */
 
 static unsigned long
 ReadLong(FILE * f)
@@ -75,7 +77,7 @@ Skip(FILE * f,
        fseek(f, distance, SEEK_CUR);
 }
 
-void
+static void
 WriteDouble(void* ptr, double d)
 {
   unsigned char result[8]="\0\0\0\0\0\0\0\0";
@@ -102,7 +104,11 @@ rd_deinit(void)
 static void
 vitosmt_read(void)
 {
-       unsigned short version                  =0;
+       long                    version                 =0;
+       long                    subversion              =0;
+       long                    check1                  =-1;
+       long                    check2                  =-2;
+       long                    check3                  =-3;
        unsigned short  stringlen               =0;
        route_head              *route_head             =0; 
        waypoint                *wpt_tmp                =0;
@@ -119,18 +125,40 @@ vitosmt_read(void)
        unsigned char   gpsvalid                =0;
        unsigned char   gpssats                 =0;
        int                             serial                  =0;
+       xml_tag *               xml_curr                =0;
        char                    buffer[80]              ="\0";
 
                
        /* 
         * 24 bytes header 
         */
-       version = ReadLong(infile);     /* 2    */
-       ReadLong(infile);                       /* 1000 */
-       count = ReadLong(infile);       /* 600  */
-       ReadLong(infile);                       /* 0    */
-       ReadLong(infile);                       /* 599  */
-       ReadLong(infile);                       /* 600  */
+       version         = ReadLong(infile);     /* 2    */
+       subversion      = ReadLong(infile);     /* 1000 */
+       count           = ReadLong(infile);     /* n    */
+       check1          = ReadLong(infile);     /* 0    */
+       check2          = ReadLong(infile);     /* n-1  */
+       check3          = ReadLong(infile);     /* n    */
+
+       if (version!=vitosmt_version) {
+       
+               fatal("%s (%d) reading file.  Unsupported version %ld.%ld\n",
+                       MYNAME, __LINE__, version, subversion );
+       }
+
+       if (subversion!=vitosmt_subversion) {
+               warning("%s (%d) reading file.  Unsafe version %ld.%ld\n",
+                       MYNAME, __LINE__, version, subversion );
+       }
+
+       if ((count!=check3)             ||
+           (check1!=count-1)   ||
+               (check2!=0)                     ||
+               (check3!=count)         ) {
+
+               fatal("%s (%d) reading file. Invalid file header\n", 
+                       MYNAME, __LINE__ );
+
+       }
 
        while (count) {
                /*
@@ -138,6 +166,8 @@ vitosmt_read(void)
                 */
                if (feof(infile)||ferror(infile)) 
                {
+                       warning("%s (%d) reading file.  Unexpected end of file %s\n",
+                               MYNAME, __LINE__, strerror(errno) );
                        break;
                }
 
@@ -181,22 +211,26 @@ vitosmt_read(void)
                        GPS Fix data
                */
                if (gpsvalid&0x7) {
-                       
-                       /* <fix> */
+                       if              (gpsfix==0)     
+                               wpt_tmp->fix            =fix_none;
                        if              (gpsfix&0x8)    
-                               wpt_tmp->fix fix_2d;
+                               wpt_tmp->fix            =fix_2d;
                        else if (gpsfix&0x10)   
-                               wpt_tmp->fix fix_3d;
+                               wpt_tmp->fix            =fix_3d;
                        else if (gpsfix&0x20)   
-                               wpt_tmp->fix = fix_dgps;
+                               wpt_tmp->fix            =fix_dgps;
+                       else
+                               wpt_tmp->fix            =fix_unknown;
                        
                        /* <sat> */
                        wpt_tmp->sat = gpssats;
                }
+               else
+                       wpt_tmp->fix            =fix_unknown;
 
                if (doing_wpts)                 /* process as waypoints */
                {
-                                       waypt_add(wpt_tmp);
+                       waypt_add(wpt_tmp);
                } 
                else if (doing_rtes)    /* process as route */
                {
@@ -224,7 +258,7 @@ vitosmt_read(void)
 static void
 wr_init(const char *fname)
 {
-       warning(MYNAME ":format is experimental and may crash Vito Navigator II.\n");
+       warning(MYNAME " write: format is experimental and may crash Vito Navigator II.\n");
        ofs = xfopen(fname, "wb", MYNAME);
 }
 
@@ -243,6 +277,7 @@ vitosmt_waypt_pr(const waypoint *waypointp)
        struct tm*              tmstructp               =0;
        double                  seconds                 =0;
        double                  worknum                 =0;
+       xml_tag*                xmltagp                 =0;
 
        ++count;
        workbuffer = xcalloc(vitosmt_datasize,1);
@@ -251,7 +286,8 @@ vitosmt_waypt_pr(const waypoint *waypointp)
        position += sizeof(double);
        WriteDouble(&workbuffer[position], (M_PI*waypointp->longitude)/180 );
        position += sizeof(double);
-       WriteDouble(&workbuffer[position], waypointp->altitude );
+       if ( waypointp->altitude-1 > unknown_alt)
+               WriteDouble(&workbuffer[position], waypointp->altitude );
        position += sizeof(double);
 
        tmstructp =  gmtime(&waypointp->creation_time);
@@ -267,54 +303,60 @@ vitosmt_waypt_pr(const waypoint *waypointp)
        position += sizeof(double);
 
        /* speed */
-       WriteDouble(&workbuffer[position], waypointp->speed / mph2mps );
+       if (waypointp->speed>0) 
+               WriteDouble(&workbuffer[position], waypointp->speed / mph2mps );
        position += sizeof(double);
        
        /* course */
-       WriteDouble(&workbuffer[position], waypointp->course );
+       if ((waypointp->course>=-360.0)&&(waypointp->course<=360.0))
+               WriteDouble(&workbuffer[position], waypointp->course );
        position += sizeof(double);
 
-
        /* pdop */
-       WriteDouble(&workbuffer[position], waypointp->pdop );
+       if (waypointp->pdop>0)
+               WriteDouble(&workbuffer[position], waypointp->pdop );
        position += sizeof(double);
 
 
        /* fix type */
-       switch (waypointp->fix) {
-               case fix_dgps:
-                       workbuffer[position++] = (unsigned char) 0x20;
-                       break;
-               case fix_3d:
-                       workbuffer[position++] = (unsigned char) 0x10;
-                       break;
-               case fix_2d:
-                       workbuffer[position++] = (unsigned char) 0x08;
-                       break;
-               default:
-                       workbuffer[position++] = (unsigned char) 0;
-                       break;
+       switch (waypointp->fix)
+       {
+       case fix_2d:
+                       workbuffer[position++] = 0x08;
+               break;
+       case fix_3d:
+                       workbuffer[position++] = 0x10;
+               break;
+       case fix_dgps:
+                       workbuffer[position++] = 0x20;
+               break;
+       default:
+                       workbuffer[position++] = 0;
+               break;
        }
+
+       /* Assume position is valid */
+       workbuffer[position++] = 0x07;
        
-       workbuffer[position++] = 0x7;
-       workbuffer[position++] = (unsigned char) waypointp->sat;
+       if ((waypointp->sat>0)&&(waypointp->sat<128))
+               workbuffer[position++] = waypointp->sat;
+       else
+               workbuffer[position++] = 0;
        
        if (fwrite(workbuffer,vitosmt_datasize,1,ofs)!=1)
        {
-               fatal("%s writing output file.  Error was '%s'.\n",
-                       MYNAME, strerror(errno));
+               fatal("%s (%d) writing output file.  Error was '%s'.\n",
+                       MYNAME, __LINE__, strerror(errno));
        }
        
        xfree(workbuffer);
 }
 
 
-void
+static void
 vitosmt_write(void)
 {
        time_t now = 0;
-       const unsigned short version                            =2;
-       const unsigned short subversion                         =1000;
        unsigned char * workbuffer                                      =0;
        size_t                  position                                        =0;
 
@@ -328,8 +370,8 @@ vitosmt_write(void)
        memset(workbuffer,0,vitosmt_headersize);
        if (fwrite(workbuffer,vitosmt_headersize,1,ofs)!=1)
        {
-               fatal("%s writing output file.  Error was '%s'.\n",
-                       MYNAME, strerror(errno));
+               fatal("%s (%d) writing output file.  Error was '%s'.\n",
+                       MYNAME, __LINE__, strerror(errno));
        }
 
        if      (doing_wpts)    /* process as waypoints */
@@ -347,9 +389,9 @@ vitosmt_write(void)
 
 
        /* write the complete the header */
-       le_write32(&workbuffer[position],version);
+       le_write32(&workbuffer[position],vitosmt_version);
        position += sizeof(gbuint32);
-       le_write32(&workbuffer[position],subversion);
+       le_write32(&workbuffer[position],vitosmt_subversion);
        position += sizeof(gbuint32);
        le_write32(&workbuffer[position],count);
        position += sizeof(gbuint32);
@@ -363,8 +405,8 @@ vitosmt_write(void)
        rewind(ofs);
        if (fwrite(workbuffer,vitosmt_headersize,1,ofs)!=1)
        {
-               fatal("%s writing output file.  Error was '%s'.\n",
-                       MYNAME, strerror(errno));
+               fatal("%s (%d) writing output file.  Error was '%s'.\n",
+                       MYNAME, __LINE__, strerror(errno));
        }
 
        xfree(workbuffer);